
local jinzhi = fk.CreateSkill{
    name = "tyj_heg__jinzhi",
}
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"
 Fk:loadTranslationTable{
      ["tyj_heg__jinzhi"]="锦织",
      [":tyj_heg__jinzhi"]="你装备区内的牌数变化后，你可令一名角色弃置一张牌，若你装备区有与之同花色的牌，其摸一张牌。",
      ["$tyj_heg__jinzhi1"] = "织锦为旗，以扬威仪。",
  ["$tyj_heg__jinzhi2"] = "坐而织锦，立则为仪。",
      ["~tyj_heg__wuban"] = "恨……杀不尽吴狗！",

      ["#tyj__jinzhi-invoke"]="是否发动 锦织 令一名角色弃置一张牌？",
    }
    jinzhi:addEffect(fk.AfterCardsMove,{
      anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(jinzhi.name) then
        local equipnum = #player:getCardIds("e")
        for _, move in ipairs(data) do
          for _, info in ipairs(move.moveInfo) do
            if move.from == player and info.fromArea == Card.PlayerEquip then
              equipnum = equipnum + 1
            elseif move.to == player and move.toArea == Card.PlayerEquip then
              equipnum = equipnum - 1
            end
          end
        end
        if #player:getCardIds("e") ~= equipnum then
          return true
        end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = table.filter(room.alive_players,function(p) return #p:getCardIds('he')>0 end )
    if #tos>0 then
      local to = room:askToChoosePlayers(player, {
        targets = tos,
        min_num = 1,
        max_num = 1,
        prompt = "#tyj__jinzhi-invoke",
        skill_name = jinzhi.name,
        cancelable = true,
      })
    if #to>0 then
      event:setCostData(self,{tos=to})
      return true
    end
  end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:doIndicate(player,{to})
    if to:isAlive() and #to:getCardIds('he') >0  then
     local disedid = room:askToDiscard(to,
      { min_num = 1, max_num = 1, skill_name = jinzhi.name, prompt = "锦织：你需要弃置一张牌", cancelable = false, include_equip = true })
       if #disedid==1 and #player:getCardIds('e')>0 then
        local realid =disedid[1]
        for _, cid in ipairs(player:getCardIds('e')) do
          if Fk:getCardById(cid).suit == Fk:getCardById(realid).suit then
            to:drawCards(1,jinzhi.name)
            break
          end
        end
       end
    end
  end,
    })
    return jinzhi